IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'spPressreleasesSelectAmmountRecordByDate') AND type in (N'P', N'PC'))
	DROP PROCEDURE spPressreleasesSelectAmmountRecordByDate
GO
-- =============================================
-- Author:		NamTP
-- Create date: Oct 21, 2014
-- Description:	Draw graph
-- Test: EXEC spPressreleasesSelectAmmountRecordByDate 'FinanceReport',32
-- =============================================
CREATE PROCEDURE spPressreleasesSelectAmmountRecordByDate
	@SourceCode VARCHAR(150),
	@LangId INT,
	@FromDate DATETIME = NULL,
	@ToDate DATETIME = NULL
AS
BEGIN
	IF @ToDate IS NULL
		BEGIN
			SET @ToDate = GETDATE()
		END			

	IF @FromDate IS NULL
		BEGIN
			SET @FromDate = DATEADD(YEAR,-1,@ToDate)
		END	
		
	SELECT CONVERT (DATE, DateTime) AS DateTime            
			,COUNT(CONVERT (DATE, DateTime)) AS Ammount
	FROM [Pressreleases]  
	WHERE [SourceCode] = @SourceCode
		AND [DateTime] BETWEEN @FromDate AND @ToDate
		AND LangId = @LangId
	GROUP BY CONVERT (DATE, DateTime),[SourceCode]
END
GO
